package com.sljy.hzk.ui.fragment.lazyfragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.ViewStubCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.Toast;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created  on 2018/1/16
 *
 * @author 唐开阔
 * @describe 懒加载fragment
 */

public abstract class LazyFragment extends Fragment {

    Unbinder unbinder;
    @SuppressLint("RestrictedApi")
    @Nullable
    @Override
    public final View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View contentView = inflater.inflate(getResId(), container, false);
        unbinder = ButterKnife.bind(this,contentView);
        onRealViewLoaded(contentView);
        return contentView;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        Log.d("LazyFragment", ">>>onDestroy---" );
    }

    /**
     * 获取真正的数据视图
     *
     * @return
     */
    protected abstract int getResId();

    /**
     * 当视图真正加载时调用
     */
    protected abstract void onRealViewLoaded(View view);

    protected void showToast(String mes) {
        Toast.makeText(getContext(), mes, Toast.LENGTH_SHORT).show();
    }


}
